<template>
    <div class="jsbosContractSelect">
        <el-input ref="reference" v-model="innerValue" type="text" :placeholder="currentPlaceholder" :disabled="disabled"
            readonly>
            <template slot="append">
                <el-button @click="clickHandle" style="min-width: 100px;" :disabled="disabled">
                    选择
                </el-button>
            </template>
        </el-input>
        <ContractPool v-if="ContractVisible" ref="ContractPool" :cId="contractId" @refreshDataList="getContractObj" />
    </div>
</template>
  
<script>
import request from "@/utils/request";
import ContractPool from "./contractPool/index.vue";
export default {
    name: "jsbosContractSelect",
    components: {
        ContractPool
    },
    props: {
        value: {
            type: [String, Array],
            default: ""
        },
        currentPlaceholder: {
            type: String,
            default: "请选择项目"
        },
        contractId: {
            type: [String, Number],
            default: ""
        },
        disabled:{
            type:Boolean,
            default:true
        }
    },
    data() {
        return {
            innerValue: '',
            ContractVisible: false,
        };
    },
    watch: {
        value(val) {
            this.setDefault();
        },
    },
    computed: {},
    created() { },
    mounted() {
        this.setDefault();
    },
    beforeDestroy() {

    },
    methods: {
        setDefault() {
            console.log('初始化', this.value);
            // 生效了
            if (this.value) {
                request({
                    url: `/api/contract/RkContractProject/` + this.value,
                    method: "GET",
                }).then((res) => {
                    // console.log('resssssssssssssssss', res.data)
                    this.$emit('getProjectData', res.data);
                    this.innerValue = res.data.projectName;
                });
            }
        },
        clickHandle() {
            if (this.contractId) {
                this.ContractVisible = true;
                this.$nextTick(() => {
                    this.$refs.ContractPool.init(this.contractId);
                });
            } else {
                this.$message({
                    message: '请先关联销售合同后再进行选择项目!',
                    type: 'warning',
                    duration: 1500
                })
            }

        },
        getContractObj(list) {
            this.emitValue(list.id);
        },
        emitValue(val) {
            this.$emit('input', val)
        }
    }
};
</script>
  